/*
 * 软件版权: 恒生电子股份有限公司
 * 修改记录:
 * 修改日期     修改人员  修改说明
 * @Version:1.0
 * ========    =======  ============================================
 * 2025/3/8  hspcadmin  com.msb.common.valid 新增
 * ========    =======  ============================================
 */
package com.msb.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;

/**
 * 功能说明:
 *
 * @author hspcadmin
 */
public class ListValueConstraintValidator implements ConstraintValidator<ListValue,Integer> {
  private HashSet<Integer> set = new HashSet<>();

  @Override
  public void initialize(ListValue constraintAnnotation) {
    int[] val = constraintAnnotation.val();
    for (int i : val) {
      set.add(i);
    }
  }

  @Override
  public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
    return set.contains(value);
  }
}
